package com.zbkj.admin.controller.platform.assistant.service.impl;

import cn.hutool.core.util.ObjUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zbkj.admin.controller.platform.assistant.service.AssistantQuickReplyService;
import com.zbkj.common.model.assistant.AssistantQuickReply;
import com.zbkj.service.assistant.model.request.AssistantQuickReplySearchRequest;
import com.zbkj.service.assistant.service.AssistantQuickReplyBaseServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class AssistantQuickReplyServiceImpl extends AssistantQuickReplyBaseServiceImpl implements AssistantQuickReplyService {

    @Override
    public PageInfo<AssistantQuickReply> getPage(AssistantQuickReplySearchRequest request) {
        PageHelper.startPage(request.getPage(), request.getLimit());
        List<AssistantQuickReply> list = super.lambdaQuery()
            .and(ObjUtil.isNotEmpty(request.getKeywords()), qw -> qw.like(AssistantQuickReply::getTitle, request.getKeywords())
                .or().like(AssistantQuickReply::getContent, request.getKeywords()))
            .ge(ObjUtil.isNotEmpty(request.getStartTime()), AssistantQuickReply::getCreateTime, request.getStartTime())
            .le(ObjUtil.isNotEmpty(request.getEndTime()), AssistantQuickReply::getCreateTime, request.getEndTime())
            .orderByAsc(AssistantQuickReply::getSort)
            .list();
        return new PageInfo<>(list);
    }

}

